package bandidong.model;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

@Entity
@Table(name = "tbl_order_details", catalog = "web_ban_di_dong_db", schema = "")
@XmlRootElement
public class OrderDetails implements Serializable {
    
    @EmbeddedId
    protected OrderDetailsPK orderDetailsPK;
    
    @NotNull
    @Column(nullable = false)
    private int amount;
    
    @JoinColumn(name = "mobile_id", referencedColumnName = "mobile_id", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private Mobile mobile;
    
    @JoinColumn(name = "order_id", referencedColumnName = "order_id", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private Orders orders;

    public OrderDetails() {
    }
    
    public OrderDetails(OrderDetailsPK orderDetailsPK, int amount) {
        this.orderDetailsPK = orderDetailsPK;
        this.amount = amount;
    }
    
    public OrderDetails(OrderDetailsPK orderDetailsPK, int amount, 
            Mobile mobile, Orders orders) {
        this(orderDetailsPK, amount);
        this.mobile = mobile;
        this.orders = orders;
    }

    public OrderDetails(int orderId, int mobileId) {
        this.orderDetailsPK = new OrderDetailsPK(orderId, mobileId);
    }

    public OrderDetailsPK getOrderDetailsPK() {
        return orderDetailsPK;
    }

    public void setOrderDetailsPK(OrderDetailsPK orderDetailsPK) {
        this.orderDetailsPK = orderDetailsPK;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }
    
    @JoinColumn(name = "mobile_id", referencedColumnName = "mobile_id", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    public Mobile getMobile() {
        return mobile;
    }

    public void setMobile(Mobile mobile) {
        this.mobile = mobile;
    }
    
    @JoinColumn(name = "order_id", referencedColumnName = "order_id", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    public Orders getOrders() {
        return orders;
    }

    public void setOrders(Orders orders) {
        this.orders = orders;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (orderDetailsPK != null ? orderDetailsPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof OrderDetails)) {
            return false;
        }
        OrderDetails other = (OrderDetails) object;
        if ((this.orderDetailsPK == null && other.orderDetailsPK != null) || (this.orderDetailsPK != null && !this.orderDetailsPK.equals(other.orderDetailsPK))) {
            return false;
        }
        return true;
    }
}
